/**
 * 自定义函数
 * */

var apiDomain = '/api/item/fxotary/front';
var apis = {
    leftmenu: { //前台菜单
        method: 'post',
        url: apiDomain + '/leftmenu',
    },
    foot: { //前台页脚
        method: 'post',
        url: apiDomain + '/foot',
    },
    home: { //前台首页
        method: 'post',
        url: apiDomain + '/home',
    },
    home2: { //前台首页2
        method: 'post',
        url: apiDomain + '/home2',
    },
    about: { //前台关于我们
        method: 'post',
        url: apiDomain + '/about',
    },
    serviceList: { //前台服务列表
        method: 'post',
        url: apiDomain + '/service/list',
    },
    serviceDetail: { //前台服务详情
        method: 'post',
        url: apiDomain + '/service/detail',
    },
    portfolioList: { //前台投资列表
        method: 'post',
        url: apiDomain + '/portfolio/list',
    },
    portfolioGrid: { //前台投资网格
        method: 'post',
        url: apiDomain + '/portfolio/grid',
    },
    portfolioDetail: { //前台投资详情
        method: 'post',
        url: apiDomain + '/portfolio/detail',
    },
    teamList: { //前台团队列表
        method: 'post',
        url: apiDomain + '/team',
    },
    blogList: { //前台博客列表
        method: 'post',
        url: apiDomain + '/blog/list',
    },
    blogGrid: { //前台博客网格
        method: 'post',
        url: apiDomain + '/blog/grid',
    },
    blogDetail: { //前台博客详情
        method: 'post',
        url: apiDomain + '/blog/detail',
    },
    contact: { //前台联系我们
        method: 'post',
        url: apiDomain + '/contact',
    },
};


(function () {
    leftMenu();
    footer();
})();


//页面菜单
function leftMenu(){
    $.ajax({
        type: apis.leftmenu.method,
        url: apis.leftmenu.url,
        data: {},
        success: function (res) {
            console.log(res);
            if (res.code < 0) {
                return
            }
            leftMenuHtml(res.data);
        },
        error: function () {
            console.log('错误辣');
        }
    });
}
//菜单拼接字符串
function leftMenuHtml(ms){
    var prefix = '/ai_items/temp/fxotary';
    var h = '', i, i2, i3, child2List, child3List;
    for (i = 0; i < ms.length; i ++) {
        child2List = ms[i].childList;
        h += '<ul>';
        if (ms[i].link == '') {
            h += '<li class="dropdown-nav">';
            h += '<a class="text_hover_animaiton" href="javascript:;">';
        } else {
            h += '<li>';
            h += '<a class="text_hover_animaiton" href="' + prefix + ms[i].link + '">';
        }
        h += ms[i].title;
        if (child2List.length > 0) {
            h += '<ul class="submenu">';
            for (i2 = 0; i2 < child2List.length; i2 ++) {
                if (child2List[i2].link == '') {
                    h += '<li class="dropdown-nav">';
                    h += '<a href="javascript:;">' + child2List[i2].title + '</a>';
                } else {
                    h += '<li>';
                    h += '<a href="' + prefix + child2List[i2].link + '">' + child2List[i2].title + '</a>';
                }
                child3List = child2List[i2].childList;
                if (child3List.length > 0) {
                    h += '<ul class="submenu">';
                    for (i3 = 0; i3 < child3List.length; i3 ++) {
                        if (child3List[i3].link == '') {
                            h += '<li><a href="javascript:;">' + child3List[i3].title + '</a></li>';
                        } else {
                            h += '<li><a href="' + prefix + child3List[i3].link + '">' + child3List[i3].title + '</a></li>';
                        }
                    }
                    h += '</ul>';
                }
                h += '</li>';
            }
            h += '</ul>';
        }
        h += '</div>';
        h += '</a>';
        h += '</li>';
        h += '</ul>';
    }
    $('#navbarNav').html(h);
}


//页脚内容
function footer(){
    $.ajax({
        type: apis.foot.method,
        url: apis.foot.url,
        data: {},
        success: function (res) {
            console.log(res);
            if (res.code < 0) {
                return
            }
            var d = res.data;
            var h = '', i;
            //1列
            h += '<div class="col-xl-4 col-sm-8 col-md-6 col-lg-4">';
            h += '<div class="footer_content">';
            h += '<a class="footer_logo" href="index.html">';
            h += '<img src="' + d.logo + '" alt="Fxotary" class="img-fluid w-100"/>';
            h += '</a>';
            h += '<p>' + d.detail + '</p>';
            h += '<ul class="d-flex flex-wrap">';
            h += '<li><a href="javascript:;"><i class="fab fa-facebook-f"></i></a></li>';
            h += '<li><a href="javascript:;"><i class="fab fa-linkedin-in"></i></a></li>';
            h += '<li><a href="javascript:;"><i class="fab fa-twitter"></i></a></li>';
            h += '<li><a href="javascript:;"><i class="fab fa-pinterest-p"></i></a></li>';
            h += '</ul>';
            h += '</div>';
            h += '</div>';
            //2列
            var menus = d.menus;
            if (menus.length > 0) {
                h += '<div class="col-xl-2 col-sm-3 col-md-6 col-lg-2">';
                h += '<ul class="footer_menu">';
                for (i = 0; i < menus.length; i ++) {
                    h += '<li>';
                    h += '<a href="' + menus[i].link + '" class="text_hover_animaiton text_hover_type_2">';
                    h += menus[i].title + '</a>';
                    h += '</li>';
                }
                h += '</ul>';
                h += '</div>';
            }
            //3列
            h += '<div class="col-xl-2 col-md-6 col-lg-3">';
            h += '<div class="footer_address">';
            h += '<h3>Address</h3>';
            h += '<p>' + d.street + '</p>';
            h += '<p>' + d.door + '</p>';
            h += '</div>';
            h += '</div>';
            //4列
            h += '<div class="col-xl-2 col-md-6 col-lg-3">';
            h += '<div class="footer_address">';
            h += '<h3>Contact</h3>';
            h += '<p>';
            h += '<a href="mailto:' + d.email + '">' + d.email + '</a>';
            h += '</p>';
            h += '<p>';
            h += '<a href="callto:' + d.phone + '">' + d.phone + '</a>';
            h += '</p>';
            h += '</div>';
            h += '</div>';
            $('#foot').html(h);
        },
        error: function () {
            console.log('错误辣');
        }
    });
}